﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<int> ints = new List<int>() { 1, 2, 3, 6, 7 };
            Delegate myDelegate = MyFunc;
            List<string> result = GetArrayResult(ints, myDelegate);
            int myId = 6;
            var lisr = ints.Where(i => i == myId);


        }
        public delegate bool DelegateCompare(int i);
        private bool Compare(int i)
        {
            return i==6;
        }

        private string MyFunc(object n, int index)
        {
            int entero = (int)n;
            return (entero * 2).ToString();
        }
        public delegate string Delegate(object n,int index);
        private static List<string> GetArrayResult(List<int> array, Delegate apuFunc)
        {
            List<string> result = new List<string>();
            foreach (var item in array)
            {
                string itemResultOperation = apuFunc(item, array.IndexOf(item));
                result.Add(itemResultOperation);
            }
            return result;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Javascript();
            return;
            int j = 7;
            MyOperation soniasOperation = new MyOperation(
                   
                   delegate(int a, int b)
                   {
                       return a + b + j;
                   }

                   );
            j = 8;
            var result = OperateTwoNumbers(2, 3,soniasOperation);
            MessageBox.Show("The result is:" + result.ToString());
        }


        private int SumTwoNumbers(int a, int b)
        {
            return a + b;
        }
        private int myInt;
        private int MultiplyTwoNumbers(int a, int b)
        {
            return a * b + myInt;
        }

        public delegate int MyOperation(int a, int b);

        private int OperateTwoNumbers(int a, int b, MyOperation operation)
        {

            return operation(a,b);

        }

        public delegate void SimpleDelegate();




        public static void Javascript()
        {

            SimpleDelegate innerFunction = delegate()
                   {
                       int var1 = 8;
                       MessageBox.Show("Inside Inner function" + var1.ToString());
                   };
            innerFunction();
        }
    }
}
